<template>
  <div>
    <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
      <span class="iconfont back-icon">&#xe624;</span>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      <router-link to="/" >
        <div class="header-left">
          <div class="iconfont back-icon">&#xe624;</div>
        </div>
      </router-link>
    <p class="header-name">景点详情</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 50) {
        const opacitynum = top / 140
        this.opacityStyle = { opacity: opacitynum }
        this.showAbs = false
      } else {
        this.showAbs = true
        console.log(this.showAbs)
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    // 全局解绑
    window.addEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
.header-abs
  position: absolute
  left: .2rem
  top: .2rem
  width: .8rem
  height: .8rem
  line-height: .8rem
  border-radius: .4rem
  text-align: center
  background: rgba(0,0,0,0.5)
  z-index: 1
  .back-icon
    display: inline-block
    padding-right: .08rem
    color: #ffffff
.header-fixed
  position: fixed
  top: 0
  left: 0
  right: 0
  height: $headerHeight
  line-height $headerHeight
  background: $bgColor
  color: #fff
  z-index: 2
  text-align: center
  .header-left
    position absolute
    width: .64rem
    float:left
    .back-icon
      color: #fff
      font-size: .35rem
  .header-name
      font-size: .35rem
</style>
